'use strict';

/**
 * @ngdoc filter
 * @name jgappApp.filter:avtarfilter
 * @function
 * @description
 * # avtarfilter
 * Filter in the jgappApp.
 */
angular.module('jgappApp')
    .filter('avtarfilter', ["openApi", function (openApi) {
        return function (input) {
            if (input) {
                return openApi.showportrait + "?imgUrl=" + input
            }
            return ""
        };
    }])
    .filter('chatfilterName', ["ChatUser", function (ChatUser) {
        return function (input) {
            if (input) {
                var userObj = ChatUser.get(input)
                if (userObj) {
                    return userObj["name"]
                } else {
                    return input;
                }
            }
            return input;
        };
    }])
    .filter('chatfilterImg', ["ChatUser", "openApi", function (ChatUser, openApi) {
        return function (input) {
            if (input) {
                var userObj = ChatUser.get(input)
                return userObj["imgUrl"]
            }
            return input;
        };
    }])
    .filter('titleFiter', ["$filter", function ($filter) {
        return function (input) {
            var title;
            if (input) {
                if (input.conversationType == "PRIVATE") {
                    title = $filter('chatfilterName')(input.targetId);
                } else {
                    title = input.conversationTitle
                }
            }

            return title;
        };
    }])
    .filter('conversationPic', ["$filter", "ChatUser", function ($filter, ChatUser) {
        return function (input) {
            var img;
            if (input) {
                if (input.conversationType == "DISCUSSION") {
                    img = ChatUser.DiscussionImg
                } else if (input.conversationType == "GROUP") {
                    img = ChatUser.GroupImg
                }
            }
            return img;
        };
    }])
